const fs = require("fs")


function myReadFile() {
    return new Promise((resolve,rejected)=>{
        fs.readFile("./data.txt",(err,data)=>{
            if(err){
                rejected(err)
                return 
            }
            console.log(data)
            resolve(data)
        })
    })
   
}
function myWriteFile(data) {
    return new Promise((resolve,rejected)=>{
        fs.writeFile('./copydata.txt',data,err=>{
            if(err){
                rejected(err)
                return 
            }
          console.log('写入成功');  
          resolve();
        })
    })
    
}

myReadFile().then(res=>{
    return myWriteFile(res)
},err=>{
    console.log("读取错误");
}).then(res=>{
    console.log('写入成功');
},err=>{
    console.log("写入错误");
})
 


